package com.veepeak.server.service;

import com.veepeak.server.common.BaseRepository;
import com.veepeak.server.common.BaseService;
import com.veepeak.server.domain.Obd;
import com.veepeak.server.domain.User;
import com.veepeak.server.domain.UserObd;
import com.veepeak.server.repository.UserObdRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class UserObdService extends BaseService<UserObd,String> {
    @Autowired
    private UserObdRepository userObdRepository;
    @Override
    public BaseRepository<UserObd, String> getRepo() {
        return this.userObdRepository;
    }

    public void deleteById(String userObdId) {
        UserObd userObd = userObdRepository.getOne(userObdId);
        userObdRepository.delete(userObd);
    }

    public List<UserObd> findByUserId(String userId) {
        List<UserObd> userObds = userObdRepository.findByUserId(userId);
        return userObds;
    }
//
//    public List<User> findByObdId(String obdId){
//        List<UserObd> userObds = userObdRepository.findByObdId(obdId);
//        List<User> userList = userObds.stream()
//                .map(userObd -> userObd.getUser()).collect(Collectors.toList());
//        return userList;
//    }
//
//    public List<UserObd> findRelationByObdId(String obdId){
//        return userObdRepository.findByObdId(obdId);
//    }
}
